package cn.fintecher.gis.web;

import cn.fintecher.gis.entity.DistrictInfo;
import cn.fintecher.gis.exception.BadRequestException;
import cn.fintecher.gis.respository.DistrictInfoRepository;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/districtInfoController")
@Api(value = "行政区信息管理", description = "行政区信息管理")
public class DistrictInfoController {

    @Autowired
    private DistrictInfoRepository districtInfoRepository;

    @GetMapping("/getDistrictList")
    @ApiOperation(value = "查询所有的行政区列表信息", notes = "查询所有的行政区列表信息")
    public ResponseEntity<List<DistrictInfo>> getDistrictList() {
        List<DistrictInfo> list = districtInfoRepository.findAll();
        return ResponseEntity.ok().body(list);
    }

    @GetMapping("/getDistrictById")
    @ApiOperation(value = "根据id查询行政区信息", notes = "根据id查询行政区信息")
    public ResponseEntity<DistrictInfo> getDistrictList(@RequestParam("id") String id) {
        DistrictInfo districtInfo = districtInfoRepository.findById(id).orElseThrow(
                () -> new BadRequestException("", "the.districtInfo.is.not.exist"));
        return ResponseEntity.ok().body(districtInfo);
    }
}
